# Build Stage
FROM whello/golang-builder:alpine AS build-stage

LABEL app="build-shippy-vessel"
LABEL REPO="https://gitee.com/whello/shippy-vessel"

ENV PROJPATH=/go/src/gitee.com/whello/shippy-vessel

# Because of https://github.com/docker/docker/issues/14914
ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
ENV GO111MODULE=on

ADD . /go/src/gitee.com/whello/shippy-vessel
WORKDIR /go/src/gitee.com/whello/shippy-vessel

RUN make build-alpine

# Final Stage
FROM golang:alpine

ARG GIT_COMMIT
ARG VERSION
LABEL REPO="https://gitee.com/whello/shippy-vessel"
LABEL GIT_COMMIT=$GIT_COMMIT
LABEL VERSION=$VERSION

# Because of https://github.com/docker/docker/issues/14914
ENV PATH=$PATH:/opt/shippy-vessel/bin

WORKDIR /opt/shippy-vessel/bin

COPY --from=build-stage /go/src/gitee.com/whello/shippy-vessel/bin/shippy-vessel /opt/shippy-vessel/bin/
RUN chmod +x /opt/shippy-vessel/bin/shippy-vessel

# Create appuser
RUN adduser -D -g '' shippy-vessel
USER shippy-vessel

ENTRYPOINT ["/usr/bin/dumb-init", "--"]

CMD ["/opt/shippy-vessel/bin/shippy-vessel"]
